<?php
session_start();
$image = imagecreatetruecolor(145,40);
$bgcolor=imagecolorallocate($image,255,255,255);
imagefill($image,0,0,$bgcolor);
$captch_code='';
for($i=0;$i<6;$i++){
    $fontsize=10;
    $fontcolor=imagecolorallocate($image,rand(0,200),rand(0,200),rand(0,200));
    $shuju='abcdefghijklmnopqrstuvwxyz1234567890';
    $fontcontent=substr($shuju,rand(0,strlen($shuju)),1);
    $captch_code.=$fontcontent;
    $x=($i*150/6)+rand(5,10);
    $y=rand(5,10);
    imagestring($image,$fontsize,$x,$y,$fontcontent,$fontcolor);
}
$_SESSION['code']=$captch_code;
for($i=0; $i < 200; $i++) { 
    $pointcolor = imagecolorallocate($image,rand(50,200),rand(50,200),rand(50,200));
    imagesetpixel($image, rand(1,144), rand(1,39), $pointcolor);
    }
for ($i=0; $i < 3; $i++) { 
        $linecolor = imagecolorallocate($image,rand(80,220),rand(80,220),rand(80,220));
        imageline($image, rand(1,144), rand(1,39),rand(1,144), rand(1,39) ,$linecolor);
    }
ob_clean();
header('content-type:image/png');
imagepng($image);
imagedestroy($image);